package com.bank.manage.controller;

import com.bank.manage.model.vo.BaseResultKeyVO;
import com.bank.manage.service.CommonService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.gavin.core.annotation.LogRecord;
import org.gavin.core.constant.CommonConst;
import org.gavin.core.domain.R;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * ApiCommonController
 *
 * @author grl
 * @date 2024/5/6
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
public class ApiCommonController {

    private final CommonService commonService;

    /**
     * 获取App端加解密公私钥
     * @param randomKey
     * @return
     */
    @GetMapping("/key")
    @LogRecord(description = "获取加密信息")
    public R<BaseResultKeyVO> getKeyPair(@Valid @RequestHeader(value = CommonConst.SAFETY_KEY)@NotBlank(message = "请求头参数"+CommonConst.SAFETY_KEY+"不能为空") @Length(min = 12,max = 45) String randomKey) {
        BaseResultKeyVO baseResultKeyVO = commonService.getKeyPair(randomKey);
        return R.ok(baseResultKeyVO);
    }

}
